/**
 * Copyright (C) 2016 Hyphenate Inc. All rights reserved.
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * http://www.apache.org/licenses/LICENSE-2.0
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.cnguifang.feigewallet.ui;

import android.app.ProgressDialog;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.support.v4.app.Fragment;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.hyphenate.EMCallBack;
import com.hyphenate.chat.EMClient;
import com.hyphenate.chat.EMOptions;
import com.cnguifang.feigewallet.Constant;
import com.cnguifang.feigewallet.DemoHelper;
import com.cnguifang.feigewallet.DemoModel;
import com.cnguifang.feigewallet.R;
import com.cnguifang.feigewallet.circle.ui.FriendCircleActivity;
import com.cnguifang.feigewallet.utils.PreferenceManager;
import com.cnguifang.feigewallet.zxing.activity.CaptureActivity;
import com.hyphenate.easeui.model.EaseCompat;
import com.hyphenate.easeui.widget.EaseSwitchButton;
import com.hyphenate.util.EMLog;

import java.io.File;
import java.util.ArrayList;

/**
 * settings screen
 */
@SuppressWarnings({"FieldCanBeLocal"})
public class FindingFragment extends Fragment implements OnClickListener {

    private RelativeLayout friendCircle;
    private RelativeLayout saoyisao;
    private RelativeLayout yaoyiyao;
    private RelativeLayout nearPeople;
    private RelativeLayout shopping;
    private RelativeLayout game;


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.em_fragment_conversation_finding, container, false);
        initLayout(view);
        return view;
    }

    private void initLayout(View view) {
        friendCircle = view.findViewById(R.id.friend_circle);
        saoyisao = view.findViewById(R.id.saoyisao);
        yaoyiyao = view.findViewById(R.id.yaoyiyao);
        nearPeople = view.findViewById(R.id.near_people);
        shopping = view.findViewById(R.id.shopping);
        game = view.findViewById(R.id.game);

        friendCircle.setOnClickListener(this);
        saoyisao.setOnClickListener(this);
        yaoyiyao.setOnClickListener(this);
        nearPeople.setOnClickListener(this);
        shopping.setOnClickListener(this);
        game.setOnClickListener(this);
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        if (savedInstanceState != null && savedInstanceState.getBoolean("isConflict", false))
            return;

    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.friend_circle:
                Intent intent = new Intent(getActivity(), FriendCircleActivity.class);
                //intent.putExtra("url", "file:///android_asset/friendCircle/index_dex.html");
                startActivity(intent);
                break;
            case R.id.saoyisao:
                Intent intent1 = new Intent(getActivity(), CaptureActivity.class);
                //intent.putExtra("url", "file:///android_asset/friendCircle/index_dex.html");
                startActivityForResult(intent1, 0x123);
                break;
            case R.id.yaoyiyao:

                break;
            case R.id.near_people:

                break;
            case R.id.shopping:

                break;
            case R.id.game:

                break;
        }
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == 0x123 && resultCode == -1) {
            if (data != null) {
                String content = data.getStringExtra("result");
                String sub = content.substring(content.lastIndexOf(":") + 1, content.length()).trim();
                Intent intent = new Intent(getActivity(), AddContactActivity.class);
                intent.putExtra("qr", sub);
                startActivity(intent);
            }
        }
    }

    @Override
    public void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        if (((MainActivity) getActivity()).isConflict) {
            outState.putBoolean("isConflict", true);
        } else if (((MainActivity) getActivity()).getCurrentAccountRemoved()) {
            outState.putBoolean(Constant.ACCOUNT_REMOVED, true);
        }
    }


}
